<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="js/jquery-1.11.0.min.js"></script>
</head>
<body>

<!--收款人姓名：<input name="add_name" id="add_name"><br>-->
<!--收款人账号：<input name="add_num" id="add_num">-->
<!--<span id="add_num_sp" style="color: red"></span><br>-->
收款人账号：<select name="add_num" id="add_num">
</select><br>
<!--<select name="add_num" id="add_num">-->
<!--</select><br>-->

选择付款账号:<select name="reduce_num" id="reduce_num">
</select><br>

转账金额：<input name="money" id="money">
<span id="money_sp" style="color: red"></span><br>

<input type="submit" style="border-radius: 5px;" value="确认转账" id="transfer">

</body>

<script>
    $("#transfer").click(function () {
        let reduce_num = $("#reduce_num").val();
        let add_num = $("#add_num").val();
        let money = $("#money").val();
        $.get("transfer", {"reduce_num": reduce_num, "add_num": add_num,"money":money}, function (data) {
            if (data=="true"){
                let a = confirm("转账成功，是否返回首页");
                if (a==true){
                    location.href="account_index.jsp";
                }
            }else {
                alert("转账失败")
            }
        },"text")
    })
    // $("#money").blur(function (){
    //     let money = $("#money").val();
    //     let reduce_num = $("#reduce_num").val();
    //     $.get("transfer3",{"money":money,"reduce_num": reduce_num},function (date){
    //         if (date=="false"){
    //             $("#money_sp").html("余额不足");
    //             return;
    //         }
    //     },"text")
    //     $("#money_sp").html("");
    // })

    $("#reduce_num").blur(function (){
        let reduce_num = $("#reduce_num").val();
        $.get("transfer1",{"reduce_num": reduce_num},function (date){
            if (date=="false"){
                $("#add_num_sp").html("无账号");
                return;
            }
        },"text")
    })
    window.onload=function (){
        $.get("transfer2",{},function (date){
            if (date==null){
                alert("无可用账号")
            }else {
                for (let i=0;i<date.length;i++){

                    $("#reduce_num").append("<option >"+date[i]+"</option>");

                }
            }
        },"json")
        $.get("transfer2",{},function (date){
            if (date==null){
                alert("无可用账号")
            }else {
                for (let i=0;i<date.length;i++){

                    $("#add_num").append("<option >"+date[i]+"</option>");

                }
            }
        },"json")
    }


</script>
</html>